home *** CD-ROM | disk | FTP | other *** search
/ PC Home 138 / PC Home issue 138.iso / Software / Essentials / Netscape / nim.xpi / bin / chrome / aim.jar / content / aim / AimAddBuddy.js < prev    next >
Encoding:
JavaScript  |  2002-10-30  |  11.7 KB  |  377 lines

  1. /*
  2.  * Function:  AimAddGroupWndOnLoad()
  3.  * Arguments: None
  4.  * Return: None
  5.  * Description:  This function is called when the user chooses to add a group and the addgroup window gets loaded.
  6.  * It sets the Ok button to do addgroup function and sets focus to the groupname text box field.
  7. */
  8.  
  9. function AimAddGroupWndOnLoad()
  10. {
  11.     doSetOKCancel(AddGroup, 0);
  12.     setTimeout("document.getElementById('fldGroupName').focus()",200);
  13. }
  14.  
  15.     // build an array of groups
  16.     // generate a list of checkboxes for each
  17.  
  18. /*
  19.  * Function:  AimAddBuddyWndOnLoad()
  20.  * Arguments: selectedGroups, tree, screenname, (optional) url-argument
  21.  * Return: None
  22.  * Description:  This function is called when the user chooses to add a buddy and the addbuddy window gets loaded.
  23.  * It builds the check box list with all the group names by calling BuildGroupFrame with selectedGroups value.
  24.  * The user can choose which groups the buddy name needs to be added to. It also sets the listSetupTree attribute
  25.  * on the window with the tree name. It sets the Ok button to do addbuddy function and sets focus to the buddyname
  26.  * text box field.
  27. */
  28.  
  29. function AimAddBuddyWndOnLoad()    
  30. {
  31.   var gps = window.arguments[0];
  32.   if (window.arguments.length > 3) {
  33.       if((window.arguments[3] != null) && (window.arguments[0] != null))  {
  34.         gps = gps.split(",");
  35.       }
  36.   }
  37.   if (isIcq() == true)
  38.   {
  39.     var icqtitle=window.document.getElementById("AimAddBuddyPanel").getAttribute("icqtitle");
  40.     window.document.getElementById("AimAddBuddyPanel").setAttribute("title", icqtitle);
  41.     icqtitle=window.document.getElementById("labelBuddyName").getAttribute("icqvalue");
  42.     window.document.getElementById("labelBuddyName").setAttribute("value", icqtitle);
  43.     window.document.getElementById("labelDisplayName").setAttribute("hidden", "false");
  44.     window.document.getElementById("fldDisplayName").setAttribute("hidden", "false");
  45.     window.document.getElementById("enterContact").setAttribute("hidden", "false");
  46.     window.document.getElementById("enterDisplay").setAttribute("hidden", "false");
  47.     window.document.getElementById("icqSearchButton").setAttribute("hidden", "false");
  48.     var icqval= document.getElementById('AddBuddyLabel').getAttribute('icqmsg', icqval);
  49.     document.getElementById('AddBuddyLabel').setAttribute('value', icqval);
  50.   }
  51.   else
  52.   {
  53.     var imtitle=window.document.getElementById("AimAddBuddyPanel").getAttribute("imtitle");
  54.     window.document.getElementById("AimAddBuddyPanel").setAttribute("title", imtitle);
  55.     imtitle=window.document.getElementById("labelBuddyName").getAttribute("imvalue");
  56.     window.document.getElementById("labelBuddyName").setAttribute("value", imtitle);
  57.     window.document.getElementById("enterDisplay").setAttribute("hidden", "true");
  58.     window.document.getElementById("labelDisplayName").setAttribute("hidden", "true");
  59.     window.document.getElementById("fldDisplayName").setAttribute("hidden", "true");
  60.     window.document.getElementById("enterContact").setAttribute("hidden", "true");
  61.     window.document.getElementById("enterDisplay").setAttribute("hidden", "true");
  62.     window.document.getElementById("icqSearchButton").setAttribute("hidden", "true");
  63.     var imval= document.getElementById('AddBuddyLabel').getAttribute('immsg', imval);
  64.     document.getElementById('AddBuddyLabel').setAttribute('value', imval);
  65.   }
  66.     top.listSetupTree = window.arguments[1];
  67.   if (isIcq())
  68.     doSetOKCancel(IcqAddContact, 0);
  69.   else
  70.       doSetOKCancel(AimAddBuddies, 0);
  71.     BuildGroupFrame(gps);
  72.     if(window.arguments[2]) {
  73.         document.getElementById("fldBuddyName").value=window.arguments[2]
  74.     return;
  75.   }
  76.   else {
  77.     setTimeout("document.getElementById('fldBuddyName').focus()",200);
  78.   }
  79.   
  80. }
  81.  
  82.  
  83. function AimAddBuddies()
  84. {
  85.     var fldBuddy = top.document.getElementById("fldBuddyName");
  86.     var buddy = fldBuddy.value;
  87.     var buddyRelative = null
  88.     var found = false;
  89.     var error = false;
  90.     var error2 = false;
  91.     var a = top.a;
  92.  
  93.   var pIAimBuddy = aimBuddyManager();
  94.   var aimIBuddy = Components.interfaces.nsIAimBuddy;
  95.   var service= new Object();
  96.  
  97.   if (!pIAimBuddy || !aimIBuddy){
  98.     aimErrorBox(aimString("msg.BadBuddy"));
  99.     return;
  100.   }
  101.  
  102.     if ( buddy == "" || !buddy ) {
  103.         aimErrorBox(aimString("msg.EnterBuddy"));
  104.         return;
  105.     }
  106.  
  107.   var isUnification=getPreaknessFlag();
  108.   var buddies = buddy.split(",");
  109.   for (var j=0; j < buddies.length; j++) {
  110.     var isAllDigits=true;
  111.     buddies[j] = buddies[j].replace(/^\s+|\s+$/g, "");
  112.     if (isUnification)
  113.     {
  114.       isAllDigits=IsIcqServiceUser(buddies[j]);
  115.       if (isAllDigits == true) {
  116.         service[j]=1;
  117.       }
  118.       else
  119.         service[j]=0;
  120.       var isInList = new Object();
  121.       aimBuddyManager().IsInBuddyList(buddies[j], isInList);
  122.       if (isAllDigits == true && isInList.value != true )
  123.       {
  124.         window.openDialog('chrome://aim/content/DisplayName.xul','_blank','modal=yes,chrome,all,centerscreen,dialog=no',j,buddies[j]);
  125.         disp[j]=document.getElementById('storageField').value;
  126.       }
  127.     }
  128.     else
  129.     {
  130.       var fldDisplay = top.document.getElementById("fldDisplayName");
  131.       var display = fldDisplay.value;
  132.       if (display) {
  133.         disp = display.split(",");
  134.         for (var j=0; j < disp.length; j++) {
  135.           // Mini Parser to extract all the display names....
  136.           disp[j] = disp[j].replace(/^\s+|\s+$/g, "");
  137.         }
  138.       } //if display
  139.     }
  140.   }
  141.  
  142.   
  143.   for ( var i=0; i < a.length; i++ ) {
  144.     if ( GetCheckBoxState( a, i ) == true ) {
  145.       found = true;
  146.       buddyRelative = FindBuddySelected( a[i], top.listSetupTree );
  147.       try {
  148.         //now add each buddies in the each group selected
  149.         for (var j=0; j < buddies.length; j++) {
  150.           if (disp[j] != null) {
  151.             aimBuddyAddBuddyAfter( a[i], buddies[j], buddyRelative, disp[j], service[j]);
  152.           }
  153.           else {
  154.             aimBuddyAddBuddyAfter( a[i], buddies[j], buddyRelative, null, service[j]);
  155.           }
  156.         }
  157.       }
  158.       catch (e) {
  159.         if (pIAimBuddy.GetnResetError() == aimIBuddy.TooManyBuddies){
  160.           aimErrorBox(aimString("msg.BigBuddyList").replace(/%MaxBudNum%/, "" + pIAimBuddy.GetMaxBudNum()));
  161.           return;
  162.         }
  163.         else
  164.           error2 = true;
  165.       } //catch
  166.     } //ifcheckbox 
  167.   } //for 
  168.   
  169.   if (error2 == true) {
  170.     aimErrorBox(aimString("msg.BadBuddy"));
  171.   }
  172.   else
  173.     if ( found == true && error == false ) {
  174.       top.window.close();
  175.     }
  176.     else if ( error == false ) {
  177.           aimErrorBox(aimString("msg.SelectGroup"));
  178.     }
  179.  
  180.  
  181. }
  182.  
  183. function IcqAddContact()
  184. {
  185.   var fldBuddy = top.document.getElementById("fldBuddyName");
  186.   var buddy = fldBuddy.value;
  187.   var buddyRelative = null
  188.   var found = false;
  189.   var error = false;
  190.   var error2 = false;
  191.   var a = top.a;
  192.  
  193.   var pIAimBuddy = aimBuddyManager();
  194.   var aimIBuddy = Components.interfaces.nsIAimBuddy;
  195.   var service= new Object();
  196.   
  197.   if (!pIAimBuddy || !aimIBuddy) {
  198.     aimErrorBox(aimString("msg.BadBuddy"));
  199.     return;
  200.   }
  201.  
  202.   if ( buddy == "" || !buddy ) {
  203.     aimErrorBox(aimString("msg.EnterBuddy"));
  204.     return;
  205.   }
  206.   
  207.   var isUnification=getPreaknessFlag();
  208.   var buddies = buddy.split(",");
  209.   for (var j=0; j < buddies.length; j++) {
  210.     var isAllDigits=true;
  211.     buddies[j] = buddies[j].replace(/^\s+|\s+$/g, "");
  212.     if (isUnification)
  213.     {
  214.       isAllDigits=IsIcqServiceUser(buddies[j]);
  215.       if (isAllDigits == true) {
  216.         service[j]=1;
  217.       }
  218.       else
  219.         service[j]=0;
  220.     }
  221.   }
  222.  
  223.     var fldDisplay = top.document.getElementById("fldDisplayName");
  224.     var display = fldDisplay.value;
  225.     var selectedGroups=0;
  226.     
  227.     for (var i=0; i < a.length; i++) {
  228.       chkboxname = "checkBox" + a[i];
  229.         chkbox = document.getElementById(chkboxname);
  230.         if ( chkbox.checked )
  231.          selectedGroups++;
  232.       }
  233.     if (selectedGroups > 1) {
  234.          // Adding same buddy to more than 1 group 
  235.         aimErrorBox(aimString("msg.MultipleGroups"));
  236.         return;
  237.       }
  238.       
  239.     for (var j=0; j < buddies.length; j++) {
  240.        var isInList = new Object();
  241.        aimBuddyManager().IsInBuddyList(buddies[j], isInList);
  242.        if ( isInList.value == true )  {
  243.         // Adding buddy who is already in contact list
  244.         aimErrorBox(aimString("msg.ExistingContact"));
  245.         return;
  246.       }
  247.     
  248.     var isInAuthList = new Object();
  249.     aimFeedbagManager().IsInAuthList(buddies[j], isInAuthList);
  250.     if ( isInAuthList.value == true )  {
  251.      // Adding buddy who is already in auth await list
  252.       aimErrorBox(aimString("msg.alreadyrequested"));
  253.       return;
  254.     }
  255.         
  256.   } //for loop
  257.  
  258.     if ( display == "" || !display ) {
  259.       // Display name field is empty!
  260.       aimErrorBox(aimString("msg.EnterDisplay"));
  261.           return;
  262.       }
  263.    
  264.     if ((display - 0) > 0) {
  265.       // Display name field should not be a number - enough with icq numbers!
  266.       aimErrorBox(aimString("msg.EnterCharDisplay"));
  267.           return;
  268.     }
  269.  
  270.       
  271.         var disp_buddies = display.split(",");
  272.         for (var j=0; j < disp_buddies.length; j++) {
  273.       // Mini Parser to extract all the display names....
  274.             disp_buddies[j] = disp_buddies[j].replace(/^\s+|\s+$/g, "");
  275.       }
  276.  
  277.   if ((buddies.length) != (disp_buddies.length)) {
  278.       // if number of buddies and number of display names do not match.
  279.       aimErrorBox(aimString("msg.MismatchDisplay"));
  280.           return;
  281.     }
  282.  
  283.     for ( var i=0; i < a.length; i++ ) {
  284.       if ( GetCheckBoxState( a, i ) == true ) {
  285.           found = true;
  286.             buddyRelative = FindBuddySelected( a[i], top.listSetupTree );
  287.             try {
  288.               //now add each buddies in the each group selected
  289.                 for (var j=0; j < buddies.length; j++) {
  290.             aimBuddyAddBuddyAfter( a[i], buddies[j], buddyRelative, disp_buddies[j], service[j] );
  291.             }
  292.                 }
  293.       catch (e) {
  294.           if (pIAimBuddy.GetnResetError() == aimIBuddy.TooManyBuddies){
  295.             aimErrorBox(aimString("msg.BigBuddyList").replace(/%MaxBudNum%/, "" + pIAimBuddy.GetMaxBudNum()));
  296.             return;
  297.           }
  298.           else
  299.                     error2 = true;
  300.       } //catch
  301.      } //ifcheckbox 
  302.     } //for 
  303.   
  304.     if (error2 == true) {
  305.         aimErrorBox(aimString("msg.BadBuddy"));
  306.     }
  307.   else
  308.     if ( found == true && error == false ) {
  309.         top.window.close();
  310.     }
  311.     else if ( error == false ) {
  312.         aimErrorBox(aimString("msg.SelectGroup"));
  313.     }
  314.  
  315. }
  316.  
  317.  
  318.  
  319.  
  320. function AddGroup()
  321. {
  322.     var fldGroup = top.document.getElementById("fldGroupName");
  323.     var group = fldGroup.value;
  324.   if (group && group != "") {
  325.     // trim the spaces before and after the group.
  326.     group = group.replace(/^\s+|\s+$/g, "");
  327.   }
  328.   if (group && group.toLowerCase() == "offline") {
  329.     aimErrorBox(aimString("msg.GroupAlreadyInList"));
  330.     return;
  331.   }
  332.     if ( group && group != "" ) {
  333.         if ( !aimBuddyAddBuddyGroup(group, null) )
  334.             top.window.close();
  335.     }
  336.     else
  337.         aimErrorBox(aimString("msg.EnterGroup"));    
  338. }
  339.  
  340. function KeyPressAddGroup(event){
  341.     if(event.keyCode== 13){
  342.         AddGroup();
  343.     }
  344. }
  345.  
  346. function AimDisplayNameWndOnLoad()
  347. {
  348.   cur_val=window.arguments[0];
  349.   cur_name=window.arguments[1];
  350.   doSetOKCancel(SetDisplay, 0);
  351. }
  352.  
  353. function SetDisplay()
  354. {
  355.   var Name=document.getElementById('dispName');
  356.   var Number=document.getElementById('dispIcq');
  357.   var sel_item=document.getElementById('dispChoices').selectedItem;
  358.   if (sel_item == Name)
  359.     disp[cur_val]=document.getElementById('fldDisplayName').value;
  360.   else
  361.     disp[cur_val]=cur_name;
  362.   top.opener.document.getElementById('storageField').value=disp[cur_val];
  363.   top.window.close();
  364. }
  365.  
  366. function IsIcqServiceUser(buddy)
  367. {
  368.   var isAllDigits = false;
  369.   var cp = new String(buddy);
  370.   if ((cp.charCodeAt(0) > 47) && (cp.charCodeAt(0) < 58)) 
  371.     // Begins with a number - icq numbers always begin with number whereas aim canNOT begin with number
  372.     isAllDigits=true;
  373.   return isAllDigits;
  374. }
  375.  
  376.  
  377.